package com.example.demo.mongo;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * *  Author:zlf
 * *  2021/3/3 10:02
 **/
@Service
public class UserService {
    @Resource
    private MongoTemplate mongoTemplate;


    public long getCount() {
        Query query = new Query();
        long count = mongoTemplate.count(query, User.class);
        return count;
    }

    public User insetUser(User user) {
        User u = mongoTemplate.insert(user);
        return u;
    }

    public void inserObject(Object o) {
        mongoTemplate.insert(o);

    }
}
